Ext.namespace("Swfu");
Ext.namespace("Swfu.BackMgr");

Swfu.BackMgr.ChgPwdWin = Ext.extend(Ext.Window,
{
    id: 'chgpwdwin', title: '修改密码', width: 330, layout: 'form', draggable: true, modal: true, frame: true, resizable: false,
    initComponent: function () {
        Ext.apply(this,
        {
            buttons: [
            {
                text: '确定', id: 'btnConfirm',
                handler: function () {
                    var chgpwdForm = Ext.getCmp('chgpwdForm');
                    if (!chgpwdForm.form.findField('oldPwd').isValid() || !chgpwdForm.form.findField('newPwd').isValid()) {
                        Ext.Msg.alert('提示', '原始密码或新密码不能为空！');
                        return
                    }
                    if (chgpwdForm.form.findField('newPwd').getValue() != chgpwdForm.form.findField('surenewpwd').getValue()) {
                        Ext.Msg.alert('提示', '两次输入密码不一致！');
                        return
                    }
                    Ext.Ajax.request(
                    {
                        url: '/EmpProfile.mvc/ChgPwd', waitMsg: '数据正在提交，请耐心等待...', waitTitle: '请等待',
                        method: 'POST', params:
                        {
                            oldPwd: chgpwdForm.form.findField('oldPwd').getValue(), newPwd: chgpwdForm.form.findField('surenewpwd').getValue()
                        },
                        success: function (response, options) {
                            var responseMessage = Ext.util.JSON.decode(response.responseText);
                            if (responseMessage.Result) {
                                Ext.getCmp('chgpwdwin').close();
                                Ext.MessageBox.alert("消息", "密码修改成功!");
                            }
                            else {
                                Ext.MessageBox.alert("消息", responseMessage.Message);
                            }
                        },
                        failure: function (response, options) {
                            Ext.MessageBox.show({
                                title: "修改失败", msg: responseMessage.Message
                            })
                        }
                    })
                }
            },
            {
                text: '取消', id: 'btnCancel',
                handler: function () {
                    Ext.getCmp('chgpwdwin').close();
                }
            }], items: [
            {
                xtype: 'form', id: 'chgpwdForm', bodyStyle: 'padding:5px', frame: true, labelWidth: 70,
                items: [
                    {
                        xtype: 'textfield', fieldLabel: '原密码', name: 'oldPwd', id: 'oldPwd', anchor: '100%',
                        width: 175, inputType: 'password', allowBlank: false, blankText: '请填写原始密码'
                    },

                    {
                        xtype: 'textfield', fieldLabel: '新密码', name: 'newPwd', id: 'newPwd', anchor: '100%',
                        width: 175, inputType: 'password', allowBlank: false, blankText: '请填写新密码'
                    },

                    {
                        fieldLabel: '确认新密码', xtype: 'textfield', name: 'surenewpwd', width: 175,
                        anchor: '100%', inputType: 'password', id: 'newPws1', allowBlank: false,
                        blankText: '请再次填写新密码'
                    }]
            }]
        });
        Swfu.BackMgr.ChgPwdWin.superclass.initComponent.apply(this, arguments)
    }
});

Ext.reg('chgpwdwin', Swfu.BackMgr.ChgPwdWin);